package com.yunding.util;

import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.Random;

/**
 * @author Sun
 * @date 2020-07-27 10:50
 */
public class Md5Util {

    public static String getPassword(String password, String salt) {
        Md5Hash md5Hash = new Md5Hash(password, salt, 1024);
        return md5Hash.toHex();
    }

    public static String getSalt(Integer n) {
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890!@#$%^&*()".toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char aChar = chars[new Random().nextInt(chars.length)];
            sb.append(aChar);
        }
        return sb.toString();
    }

}
